$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/message/list',
        datatype: "json",
        colModel: [			
			{ label: '发送人', name: 'fromusername', index: "userguid", width: 45, key: true },
			{ label: '内容', name: 'content', width: 300 },
			{ label: '发送时间', name: 'createTime', index: "create_time", width: 85},
			{ label: '回复', name: 'messageguid', sortable: false, width: 60, formatter: function(value, options, row){
				 return '<button type="button" class="like btn btn-primary  btn-sm" style="margin-right:15px;" onclick="vm.authorization(\''+value+'\')" >回复</button>'
			}},
			{ label: '主键', name: 'messageguid', index: 'messageguid', hidden: true}
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
    el:'#rrapp',
    data:{
        q:{
        	fromusername: null
        },
        showList: true,
        title:null
    },
    methods: {
        query: function () {
            vm.reload();
        },
        del: function () {
            var userguids = getSelectedRows();
            if(userguids == null){
                return ;
            }
            confirm('确定要删除选中的记录？', function(){
                $.ajax({
                    type: "POST",
                    url: baseURL + "sys/message/delete",
                    contentType: "application/json",
                    data: JSON.stringify(userguids),
                    success: function(r){
                        if(r.code == 0){
                            alert('操作成功', function(){
                                vm.reload();
                            });
                        }else{
                            alert(r.msg);
                        }
                    }
                });
            });
        },
        
        reload: function () {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{
                postData:{'fromusername': vm.q.fromusername},
                page:page
            }).trigger("reloadGrid");
        }
    }
});